
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>mysql主从同步与读写分离 · tgor note</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.3">
        <meta name="author" content="tgor">
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-splitter/splitter.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-tbfed-pagefooter/footer.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-page-toc-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search-pro/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-back-to-top-button/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-code/plugin.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="../Java-Spring/SpringBoot事务注解@Transactional.html" />
    
    
    <link rel="prev" href="mysql性能测试.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    Me
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="../category/微服务.html">
            
                <a href="../category/微服务.html">
            
                    
                    微服务
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.2.1" data-path="../Java-Spring/Feign.html">
            
                <a href="../Java-Spring/Feign.html">
            
                    
                    HTTP客户端Feign
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.2" data-path="../Java-其他库/限流.html">
            
                <a href="../Java-其他库/限流.html">
            
                    
                    限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    限流Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.4" data-path="../Java-Spring/负载均衡.html">
            
                <a href="../Java-Spring/负载均衡.html">
            
                    
                    负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.5" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    负载均衡Nginx
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.6" data-path="../Java-其他库/熔断Hystrix.html">
            
                <a href="../Java-其他库/熔断Hystrix.html">
            
                    
                    熔断Hystrix
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.7" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html">
            
                    
                    缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.8" data-path="../Java-其他库/缓存.html">
            
                <a href="../Java-其他库/缓存.html#本地缓存">
            
                    
                    本地缓存
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.9" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    分布式缓存Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.10" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html">
            
                    
                    分布式事务
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.11" data-path="../Java-其他库/分布式事务.html">
            
                <a href="../Java-其他库/分布式事务.html#事务消息">
            
                    
                    可靠事务消息
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.12" data-path="../Java-Spring/业务监控.html">
            
                <a href="../Java-Spring/业务监控.html">
            
                    
                    业务监控
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.13" data-path="../Java-其他库/分布式定时作业.html">
            
                <a href="../Java-其他库/分布式定时作业.html">
            
                    
                    分布式作业调度ElasticJob
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.14" data-path="../Java-ORM/ORM.html">
            
                <a href="../Java-ORM/ORM.html">
            
                    
                    ORM
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.15" data-path="../Java-其他库/分布式系统及CAP原理.html">
            
                <a href="../Java-其他库/分布式系统及CAP原理.html">
            
                    
                    分布式系统及CAP原理
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2.16" data-path="../MQ/RabbitMQ笔记.html">
            
                <a href="../MQ/RabbitMQ笔记.html">
            
                    
                    消息驱动Rabbitmq
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="../category/数据库.html">
            
                <a href="../category/数据库.html">
            
                    
                    数据库
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.3.1" data-path="经典数据库设计案例.html">
            
                <a href="经典数据库设计案例.html">
            
                    
                    mysql设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.2" data-path="Mysql事务与锁.html">
            
                <a href="Mysql事务与锁.html">
            
                    
                    mysql事务与锁
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.3" data-path="mysql数据类型.html">
            
                <a href="mysql数据类型.html">
            
                    
                    mysql数据类型
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.4" data-path="mysql索引及查询.html">
            
                <a href="mysql索引及查询.html">
            
                    
                    mysql索引与查询
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.5" data-path="mysql索引及查询.html">
            
                <a href="mysql索引及查询.html#查询语句设计准则">
            
                    
                    mysql查询语句设计准则
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.6" data-path="mysql性能测试.html">
            
                <a href="mysql性能测试.html">
            
                    
                    mysql性能测试
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.3.7" data-path="mysql主从同步与读写分离.html">
            
                <a href="mysql主从同步与读写分离.html">
            
                    
                    mysql主从同步与读写分离
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.8" data-path="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html">
            
                    
                    Spring事务注解@Transactional
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.9" data-path="../数据结构与算法/位运算应用实例.html">
            
                <a href="../数据结构与算法/位运算应用实例.html">
            
                    
                    位运算应用实例
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.10" data-path="../Mongodb-Client/morphia-API汇总.html">
            
                <a href="../Mongodb-Client/morphia-API汇总.html">
            
                    
                    morphia API汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.11" data-path="../Mongodb-Client/mongo驱动连接.html">
            
                <a href="../Mongodb-Client/mongo驱动连接.html">
            
                    
                    mongodb驱动与连接
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.12" data-path="../Mongodb/mongodb-ObjectId实践.html">
            
                <a href="../Mongodb/mongodb-ObjectId实践.html">
            
                    
                    mongodb ObjectId实践
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3.13" data-path="../Mongodb/mongodb角色权限.html">
            
                <a href="../Mongodb/mongodb角色权限.html">
            
                    
                    mongodb角色权限
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.4" data-path="../category/java并发.html">
            
                <a href="../category/java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.4.1" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html">
            
                    
                    Java并发
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.2" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#锁">
            
                    
                    Java并发之锁设计
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.3" data-path="../Java-Base/Java并发.html">
            
                <a href="../Java-Base/Java并发.html#synchronized">
            
                    
                    Java并发之synchronized
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.4" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantlock">
            
                    
                    Java Lock之ReentrantLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.5" data-path="../Java-Base/Java之Lock.html">
            
                <a href="../Java-Base/Java之Lock.html#reentrantreadwritelock">
            
                    
                    Java Lock之ReentrantReadWriteLock
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.6" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html">
            
                    
                    Java Future
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.7" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#futuretask">
            
                    
                    Java Future之FutureTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.8" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#completablefuture">
            
                    
                    Java Future之CompletableFuture
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.9" data-path="../Java-Base/Java之Future.html">
            
                <a href="../Java-Base/Java之Future.html#forkjointask">
            
                    
                    Java Future之ForkJoinTask
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.4.10" data-path="../Java-Base/Java之Thread.html">
            
                <a href="../Java-Base/Java之Thread.html">
            
                    
                    Java Thread
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="../category/redis.html">
            
                <a href="../category/redis.html">
            
                    
                    Redis
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.5.1" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html">
            
                    
                    Redis
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.2" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#集群">
            
                    
                    Redis集群
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.3" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#消息订阅">
            
                    
                    Redis消息订阅
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.4" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#lua">
            
                    
                    Redis Lua脚本
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5.5" data-path="../Redis/Redis.html">
            
                <a href="../Redis/Redis.html#配置汇总">
            
                    
                    Redis配置汇总
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="../category/运维.html">
            
                <a href="../category/运维.html">
            
                    
                    运维
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.6.1" data-path="../运维/Linux常用操作汇总.html">
            
                <a href="../运维/Linux常用操作汇总.html">
            
                    
                    Linux常用操作汇总
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6.2" data-path="../运维/阿里云笔记.html">
            
                <a href="../运维/阿里云笔记.html">
            
                    
                    阿里云笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="../category/nginx.html">
            
                <a href="../category/nginx.html">
            
                    
                    Nginx
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.7.1" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html">
            
                    
                    Nginx基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.2" data-path="../运维/Nginx负载均衡.html">
            
                <a href="../运维/Nginx负载均衡.html">
            
                    
                    Nginx负载均衡
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.3" data-path="../运维/Nginx限流.html">
            
                <a href="../运维/Nginx限流.html">
            
                    
                    Nginx限流
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7.4" data-path="../运维/Nginx学习笔记.html">
            
                <a href="../运维/Nginx学习笔记.html#六、其他">
            
                    
                    Nginx客户端辅助技巧
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="../category/容器化.html">
            
                <a href="../category/容器化.html">
            
                    
                    容器化
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.8.1" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html">
            
                    
                    Docker学习笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.2" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#基础操作">
            
                    
                    Docker基础操作
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8.3" data-path="../Docker/docker笔记.html">
            
                <a href="../Docker/docker笔记.html#dockerfile">
            
                    
                    DockerFile
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="../category/Web.html">
            
                <a href="../category/Web.html">
            
                    
                    Web
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.9.1" data-path="../运维/Http入坑Https笔记.html">
            
                <a href="../运维/Http入坑Https笔记.html">
            
                    
                    Http入坑Https笔记
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9.2" data-path="../Web/阿里云OSS.html">
            
                <a href="../Web/阿里云OSS.html">
            
                    
                    OSS
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="../category/java基础.html">
            
                <a href="../category/java基础.html">
            
                    
                    Java基础
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.10.1" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#jvm">
            
                    
                    JVM基础
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.2" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#语法糖">
            
                    
                    Java语法糖
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.3" data-path="../Java-Base/Java基础.html">
            
                <a href="../Java-Base/Java基础.html#数据结构">
            
                    
                    Java数据结构
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.4" data-path="../Java-Base/Java8函数式编程.html">
            
                <a href="../Java-Base/Java8函数式编程.html">
            
                    
                    java8函数式编程
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.5" data-path="../Java-Base/ArrayList源码分析.html">
            
                <a href="../Java-Base/ArrayList源码分析.html">
            
                    
                    JDK源码分析ArrayList
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.6" data-path="../Java-Base/HashMap源码分析.html">
            
                <a href="../Java-Base/HashMap源码分析.html">
            
                    
                    JDK源码分析HashMap
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.7" data-path="../Java-Base/Java注解.html">
            
                <a href="../Java-Base/Java注解.html">
            
                    
                    Java注解
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.8" data-path="../Java-Base/Timsort排序算法.html">
            
                <a href="../Java-Base/Timsort排序算法.html">
            
                    
                    Timsort排序算法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10.9" data-path="../Java-Base/插入排序分析与Java实现.html">
            
                <a href="../Java-Base/插入排序分析与Java实现.html">
            
                    
                    插入排序分析与Java实现
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="../category/工具与规范.html">
            
                <a href="../category/工具与规范.html">
            
                    
                    工具与规范
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.11.1" data-path="../工具/Maven使用技巧汇总.html">
            
                <a href="../工具/Maven使用技巧汇总.html">
            
                    
                    Maven使用技巧
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11.2" data-path="../编码规范/Java编码规范.html">
            
                <a href="../编码规范/Java编码规范.html">
            
                    
                    Java编码规范
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="../category/OLAP.html">
            
                <a href="../category/OLAP.html">
            
                    
                    OLAP
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.12.1" data-path="../数据处理/storm学习笔记.html">
            
                <a href="../数据处理/storm学习笔记.html">
            
                    
                    流式计算Storm学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="../category/数据运营.html">
            
                <a href="../category/数据运营.html">
            
                    
                    数据运营
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.13.1" data-path="../数据运营/增长黑客数据运营.html">
            
                <a href="../数据运营/增长黑客数据运营.html">
            
                    
                    增长黑客-数据运营
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="../category/前端技术栈.html">
            
                <a href="../category/前端技术栈.html">
            
                    
                    前端技术栈
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.14.1" data-path="../前端/JavaScript设计模式.html">
            
                <a href="../前端/JavaScript设计模式.html">
            
                    
                    JavaScript设计模式
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.2" data-path="../前端/html相对路径与绝对路径.html">
            
                <a href="../前端/html相对路径与绝对路径.html">
            
                    
                    Html相对路径与绝对路径
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14.3" data-path="../前端/微信小程序学习笔记.html">
            
                <a href="../前端/微信小程序学习笔记.html">
            
                    
                    微信小程序学习笔记
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="../category/个人.html">
            
                <a href="../category/个人.html">
            
                    
                    个人
            
                </a>
            

            
            <ul class="articles">
                
    
        <li class="chapter " data-level="1.15.1" data-path="../个人/简历.html">
            
                <a href="../个人/简历.html">
            
                    
                    简历
            
                </a>
            

            
        </li>
    

            </ul>
            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >mysql主从同步与读写分离</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <h1 id="mysql&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x4E0E;&#x8BFB;&#x5199;&#x5206;&#x79BB;">mysql&#x4E3B;&#x4ECE;&#x540C;&#x6B65;&#x4E0E;&#x8BFB;&#x5199;&#x5206;&#x79BB;</h1>
<h2 id="&#x590D;&#x5236;&#x6D41;&#x7A0B;">&#x590D;&#x5236;&#x6D41;&#x7A0B;</h2>
<p><img src="assets/image-20200429102732255.png" alt="image-20200429102732255"></p>
<ol>
<li>master&#x542F;&#x7528;&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#xFF0C;&#x8BB0;&#x5F55;<strong>&#x4EFB;&#x4F55;</strong>&#x4FEE;&#x6539;&#x6570;&#x636E;&#x5E93;&#x6570;&#x636E;&#x7684;&#x4E8B;&#x4EF6;</li>
<li>slave&#x5F00;&#x542F;<strong>IO&#x7EBF;&#x7A0B;</strong>&#xFF0C;&#x901A;&#x8FC7;<strong>mysql&#x534F;&#x8BAE;</strong>&#xFF0C;<strong>&#x4E3B;&#x52A8;&#x8BF7;&#x6C42;</strong>master&#x7684;&#x65E5;&#x5FD7;</li>
<li>slave&#x63A5;&#x6536;master&#x65E5;&#x5FD7;&#xFF0C;&#x5E76;&#x653E;&#x5230;&#x4E2D;&#x7EE7;&#x65E5;&#x5FD7;relay log&#x3010;&#x6CE8;&#x610F;&#xFF1A;&#x5982;&#x4F55;&#x4FDD;&#x8BC1;&#x4E00;&#x81F4;&#x6027;&#xFF1F;&#x3011;</li>
<li>slave&#x5F00;&#x542F;<strong>sql&#x7EBF;&#x7A0B;</strong>&#xFF0C;&#x4ECE;relay log&#x4E2D;&#x8BFB;&#x53D6;&#xFF0C;&#x5E76;&#x6267;&#x884C;</li>
</ol>
<h2 id="&#x914D;&#x7F6E;&#x65B9;&#x6CD5;">&#x914D;&#x7F6E;&#x65B9;&#x6CD5;</h2>
<h3 id="&#x601D;&#x8DEF;">&#x601D;&#x8DEF;</h3>
<ol>
<li>&#x4E3B;&#x8282;&#x70B9;</li>
</ol>
<h3 id="docker&#x521B;&#x5EFA;&#x5BB9;&#x5668;">Docker&#x521B;&#x5EFA;&#x5BB9;&#x5668;</h3>
<pre><code class="lang-shell">#master
#&#x6620;&#x5C04;&#x7AEF;&#x53E3;3312
#&#x6620;&#x5C04;my.cnf&#x5230;/master_slave_config/master.cnf
docker run -i -t --name mysql-master -p 3312:3306 -v /app/mysql/master_slave_config/master.cnf:/etc/my.cnf -d mysql/mysql-server:5.7.26

#slave
#&#x6620;&#x5C04;&#x7AEF;&#x53E3;3313
#&#x6620;&#x5C04;my.cnf&#x5230;/master_slave_config/slave.cnf
docker run -i -t --name mysql-slave -p 3313:3306 --link mysql-master:mysql-master -m 300M -v /app/mysql/master_slave_config/slave.cnf:/etc/my.cnf -d mysql/mysql-server:5.7.26
</code></pre>
<h3 id="master&#x914D;&#x7F6E;">master&#x914D;&#x7F6E;</h3>
<p>master&#x7684;my.cnf&#x914D;&#x7F6E;</p>
<pre><code class="lang-conf">log-bin=mysql-bin
binlog_format=mixed
server-id=1
innodb_file_per_table=ON
skip_name_resolve=ON
</code></pre>
<h4 id="&#x67E5;&#x770B;binlog&#x5F00;&#x542F;&#x72B6;&#x6001;">&#x67E5;&#x770B;binlog&#x5F00;&#x542F;&#x72B6;&#x6001;</h4>
<pre><code>mysql&gt; SHOW GLOBAL VARIABLES LIKE &apos;%log%&apos;;

+--------------------------------------------+---------------------------------------------+
| Variable_name                              | Value                                       |
+--------------------------------------------+---------------------------------------------+
| log_bin                                    | **ON**                                          |
| log_bin_basename                           | /var/lib/mysql/mysql-bin                    |
| log_bin_index                              | /var/lib/mysql/mysql-bin.index              |
| log_bin_trust_function_creators            | OFF                                         |
+--------------------------------------------+---------------------------------------------+
</code></pre><h4 id="&#x67E5;&#x770B;master&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x5217;&#x8868;">&#x67E5;&#x770B;master&#x4E8C;&#x8FDB;&#x5236;&#x65E5;&#x5FD7;&#x5217;&#x8868;</h4>
<p>fileSize&#x5355;&#x4F4D;&#xFF1A;</p>
<pre><code>mysql&gt; show master logs;
+------------------+-----------+
| Log_name         | File_size |
+------------------+-----------+
| mysql-bin.000001 |       177 |
| mysql-bin.000002 |       177 |
| mysql-bin.000003 |      1228 |
+------------------+-----------+
</code></pre><h4 id="&#x67E5;&#x770B;&#x4E3B;&#x8282;&#x70B9;&#x7684;server-id">&#x67E5;&#x770B;&#x4E3B;&#x8282;&#x70B9;&#x7684;server-id</h4>
<pre><code class="lang-mysql">mysql&gt; show global variables like &apos;%server%&apos;;
+---------------------------------+--------------------------------------+
| Variable_name                   | Value                                |
+---------------------------------+--------------------------------------+
| character_set_server            | latin1                               |
| collation_server                | latin1_swedish_ci                    |
| innodb_ft_server_stopword_table |                                      |
| server_id                       | 1                                    |
| server_id_bits                  | 32                                   |
| server_uuid                     | 3f2e5eed-89c8-11ea-ab1c-0242ac110003 |
+---------------------------------+--------------------------------------+
</code></pre>
<h4 id="&#x521B;&#x5EFA;&#x6709;&#x590D;&#x5236;&#x6743;&#x9650;&#x7684;&#x7528;&#x6237;">&#x521B;&#x5EFA;&#x6709;&#x590D;&#x5236;&#x6743;&#x9650;&#x7684;&#x7528;&#x6237;</h4>
<pre><code class="lang-mysql">GRANT REPLICATION SLAVE,REPLICATION CLIENT ON *.* TO &apos;repluser&apos;@&apos;%&apos; IDENTIFIED BY &apos;504&apos; WITH GRANT OPTION;

flush privileges;
</code></pre>
<h3 id="slave&#x914D;&#x7F6E;">slave&#x914D;&#x7F6E;</h3>
<h4 id="&#x67E5;&#x770B;relaylog">&#x67E5;&#x770B;relayLog</h4>
<pre><code class="lang-mysql">mysql&gt; SHOW GLOBAL VARIABLES LIKE &apos;%log%&apos;;
+--------------------------------------------+--------------------------------------+
| Variable_name                              | Value                                |
+--------------------------------------------+--------------------------------------+
| log_bin                                    | OFF                                  |
| relay_log                                  | relay-log                            |
| relay_log_basename                         | /var/lib/mysql/relay-log             |
| relay_log_index                            | /var/lib/mysql/relay-log.index
</code></pre>
<h4 id="change-master&#x8BBF;&#x95EE;&#x4FE1;&#x606F;">change master&#x8BBF;&#x95EE;&#x4FE1;&#x606F;</h4>
<pre><code class="lang-mysql">#&#x6CE8;&#x610F;&#xFF1A;&#x5F53;&#x901A;&#x8FC7;docker&#x5BB9;&#x5668;&#x8BBF;&#x95EE;&#x65F6;&#xFF0C;master_port&#x5E94;&#x4E3A;&#x5BB9;&#x5668;&#x5185;&#x90E8;&#x7AEF;&#x53E3;&#xFF0C;&#x975E;&#x6620;&#x5C04;&#x5916;&#x90E8;&#x7AEF;&#x53E3;
CHANGE MASTER TO MASTER_HOST=&apos;mysql-master&apos;,MASTER_PORT=3306,MASTER_USER=&apos;repluser&apos;,MASTER_PASSWORD=&apos;504&apos;, MASTER_LOG_FILE=&apos;mysql-bin.000003&apos;,MASTER_LOG_POS=2646;
</code></pre>
<h4 id="&#x68C0;&#x67E5;io&#x4E0E;sql&#x7EBF;&#x7A0B;&#x542F;&#x52A8;&#x72B6;&#x6001;">&#x68C0;&#x67E5;IO&#x4E0E;SQL&#x7EBF;&#x7A0B;&#x542F;&#x52A8;&#x72B6;&#x6001;</h4>
<pre><code class="lang-mysql">mysql&gt; show slave status\G;
*************************** 1. row ***************************
               Slave_IO_State: 
                  Master_Host: 127.0.0.1
                  Master_User: repluser
                  Master_Port: 3306
                Connect_Retry: 60
              Master_Log_File: mysql-bin.000003
          Read_Master_Log_Pos: 1723
               Relay_Log_File: relay-log.000001
                Relay_Log_Pos: 4
        Relay_Master_Log_File: mysql-bin.000003
             Slave_IO_Running: No
            Slave_SQL_Running: No
</code></pre>
<h4 id="&#x542F;&#x52A8;io&#x4E0E;sql&#x7EBF;&#x7A0B;">&#x542F;&#x52A8;IO&#x4E0E;SQL&#x7EBF;&#x7A0B;</h4>
<pre><code class="lang-mysql">mysql&gt; start slave;
</code></pre>
<h4 id="&#x540C;&#x6B65;&#x5931;&#x8D25;&#x539F;&#x56E0;&#x6392;&#x67E5;">&#x540C;&#x6B65;&#x5931;&#x8D25;&#x539F;&#x56E0;&#x6392;&#x67E5;</h4>
<p>&#x901A;&#x8FC7;<code>show slave status\G;</code>&#x68C0;&#x67E5;IO&#x4E0E;SQL&#x7EBF;&#x7A0B;&#x8FD0;&#x884C;&#x60C5;&#x51B5;&#xFF0C;&#x5982;&#x679C;&#x90FD;&#x4E3A;YES&#xFF0C;&#x90E8;&#x7F72;&#x6210;&#x529F;&#xFF0C;&#x5F53;&#x5982;&#x679C;&#x4ECD;&#x7136;&#x672A;&#x80FD;&#x901A;&#x8FC7;&#x6570;&#x636E;&#xFF0C;&#x5E94;&#x68C0;&#x67E5;master&#x4E0E;slave&#x7684;&#x6570;&#x636E;&#x5E93;&#x4E0E;&#x8868;&#x7ED3;&#x6784;&#x662F;&#x5426;&#x4E00;&#x81F4;&#xFF0C;&#x4E3B;&#x4ECE;&#x4E0D;&#x4F1A;&#x540C;&#x6B65;&#x8868;&#x5217;&#x8868;&#x4E0E;&#x8868;&#x7ED3;&#x6784;&#xFF0C;&#x542F;&#x7528;&#x540C;&#x6B65;&#x524D;&#xFF0C;&#x5E94;&#x4FDD;&#x8BC1;&#x4E3B;&#x4ECE;&#x8282;&#x70B9;&#x7684;&#x4E00;&#x81F4;</p>
<p>&#x53CD;&#x4E4B;&#xFF0C;&#x5982;&#x679C;&#x51FA;&#x73B0;<code>Slave_IO_Running: NO</code>&#x7684;&#x72B6;&#x6001;&#xFF0C;&#x8868;&#x793A;&#x4E3B;&#x4ECE;&#x4E4B;&#x95F4;&#x8FDE;&#x63A5;&#x4E0D;&#x901A;&#xFF0C;&#x8003;&#x8651;&#x4EE5;&#x4E0B;&#x60C5;&#x51B5;&#xFF1A;          </p>
<ol>
<li>ping&#x4E0D;&#x901A;&#xFF0C;&#x901A;&#x8FC7;docker link&#x89E3;&#x51B3;</li>
<li>master&#x540C;&#x6B65;&#x8D26;&#x6237;repluser&#x7684;&#x57DF;&#x4E3A;localhost&#x95EE;&#x9898;&#xFF0C;&#x901A;&#x8FC7;&#x57DF;&#x6539;&#x4E3A;<code>%</code>&#x53EF;&#x4EE5;&#x89E3;&#x51B3;</li>
<li>&#x540C;&#x6B65;&#x65E5;&#x5FD7;&#x7684;&#x4F4D;&#x7F6E;&#x4E0D;&#x6B63;&#x786E;&#xFF0C;&#x67E5;&#x770B;master&#x7684;position&#xFF1A;<code>show master status</code>&#xFF0C;slave&#x8282;&#x70B9;change master&#x5E94;&#x4E3A;&#x5BF9;&#x5E94;position</li>
<li><strong>&#x91CD;&#x8981;</strong>&#xFF1A;&#x5F53;&#x91C7;&#x7528;Docker&#x5BB9;&#x5668;&#x95F4;&#x4E92;&#x8FDE;&#x65B9;&#x6848;&#x65F6;&#xFF0C;slave&#x8282;&#x70B9;change master&#x547D;&#x4EE4;&#x8FDE;&#x63A5;&#x4E3B;&#x8282;&#x70B9;&#x7AEF;&#x53E3;&#x5E94;&#x4E3A;3306&#xFF08;master&#x4E2D;mysql&#x7684;&#x7AEF;&#x53E3;&#xFF09;&#xFF0C;&#x800C;&#x4E0D;&#x662F;&#x6620;&#x5C04;&#x7684;&#x7269;&#x7406;&#x673A;&#x7684;&#x7AEF;&#x53E3;</li>
</ol>
<p>&#x4F8B;&#x5982;</p>
<p>master&#x5BB9;&#x5668;&#xFF1A;<code>docker --name mysql-master -p3312:3306...</code></p>
<p>slave&#x5BB9;&#x5668;change master&#x5E94;&#x4E3A;&#xFF1A;<code>CHANGE MASTER TO MASTER_HOST=&apos;mysql-master&apos;,master_port=3306...</code></p>
<h4 id="&#x6D4B;&#x8BD5;&#x540C;&#x6B65;&#x6210;&#x529F;">&#x6D4B;&#x8BD5;&#x540C;&#x6B65;&#x6210;&#x529F;</h4>
<pre><code class="lang-sql"><span class="hljs-keyword">CREATE</span> <span class="hljs-keyword">TABLE</span> <span class="hljs-string">`account`</span> (<span class="hljs-string">`id`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>),<span class="hljs-string">`amount`</span> <span class="hljs-built_in">int</span>(<span class="hljs-number">11</span>),PRIMARY <span class="hljs-keyword">KEY</span> (<span class="hljs-string">`id`</span>)) <span class="hljs-keyword">ENGINE</span>=<span class="hljs-keyword">InnoDB</span> <span class="hljs-keyword">DEFAULT</span> <span class="hljs-keyword">CHARSET</span>=utf8mb4;

<span class="hljs-keyword">insert</span> <span class="hljs-keyword">into</span> <span class="hljs-string">`account`</span> (<span class="hljs-keyword">id</span>, amount) <span class="hljs-keyword">values</span> (<span class="hljs-number">2</span>, <span class="hljs-number">45</span>);
</code></pre>
<h2 id="mybatis&#x914D;&#x7F6E;&#x8BFB;&#x5199;&#x5206;&#x79BB;">mybatis&#x914D;&#x7F6E;&#x8BFB;&#x5199;&#x5206;&#x79BB;</h2>
<p><a href="../Java-ORM/ORM.html#&#x8BFB;&#x5199;&#x5206;&#x79BB;">mybatis&#x914D;&#x7F6E;&#x8BFB;&#x5199;&#x5206;&#x79BB;</a></p>
<h2 id="&#x5F85;&#x89E3;&#x51B3;&#x95EE;&#x9898;">&#x5F85;&#x89E3;&#x51B3;&#x95EE;&#x9898;</h2>
<ol>
<li>&#x7EBF;&#x4E0A;&#x4E3B;&#x4ECE;&#x590D;&#x5236;&#x9047;&#x5230;&#x8FC7;&#x4EC0;&#x4E48;&#x95EE;&#x9898;</li>
<li>&#x6570;&#x636E;&#x4E0D;&#x4E00;&#x81F4;&#x60C5;&#x51B5;&#x5982;&#x4F55;&#x89E3;&#x51B3;</li>
<li>&#x4E3B;&#x4ECE;&#x6A21;&#x5F0F; </li>
</ol>
<footer class="page-footer"><span class="copyright">Copyright &#xA9; tgor.top 2019 all right reserved&#xFF0C;powered by Gitbook</span><span class="footer-modification">&#x8BE5;&#x6587;&#x4EF6;&#x4FEE;&#x8BA2;&#x65F6;&#x95F4;&#xFF1A;
2020-04-29 16:20:40
</span></footer>
<script>console.log("plugin-popup....");document.onclick = function(e){ e.target.tagName === "IMG" && window.open(e.target.src,e.target.src)}</script><style>img{cursor:pointer}</style>
                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="mysql性能测试.html" class="navigation navigation-prev " aria-label="Previous page: mysql性能测试">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="../Java-Spring/SpringBoot事务注解@Transactional.html" class="navigation navigation-next " aria-label="Next page: Spring事务注解@Transactional">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"mysql主从同步与读写分离","level":"1.3.7","depth":2,"next":{"title":"Spring事务注解@Transactional","level":"1.3.8","depth":2,"path":"Java-Spring/SpringBoot事务注解@Transactional.md","ref":"Java-Spring/SpringBoot事务注解@Transactional.md","articles":[]},"previous":{"title":"mysql性能测试","level":"1.3.6","depth":2,"path":"Mysql/mysql性能测试.md","ref":"Mysql/mysql性能测试.md","articles":[]},"dir":"ltr"},"config":{"plugins":["chapter-fold","splitter","tbfed-pagefooter","page-toc-button","-search","search-pro","popup","back-to-top-button","code","copy-code-button"],"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"pluginsConfig":{"tbfed-pagefooter":{"copyright":"Copyright &copy tgor.top 2019","modify_label":"该文件修订时间：","modify_format":"YYYY-MM-DD HH:mm:ss"},"chapter-fold":{},"splitter":{},"search-pro":{"cutWordLib":"nodejieba","defineWord":["Gitbook Use"]},"popup":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"code":{"copyButtons":true},"fontsettings":{"theme":"sepia","family":"serif","size":1},"highlight":{},"page-toc-button":{"maxTocDepth":2,"minTocSize":2},"back-to-top-button":{},"copy-code-button":{},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"theme":"default","author":"tgor","pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"variables":{},"title":"tgor note","gitbook":"*","description":"tgor生活工作记录"},"file":{"path":"Mysql/mysql主从同步与读写分离.md","mtime":"2020-04-29T08:20:40.800Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2020-04-29T08:43:24.127Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-chapter-fold/chapter-fold.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-splitter/splitter.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-page-toc-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/jquery.mark.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search-pro/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-back-to-top-button/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-code/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-copy-code-button/toggle.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

